package com.yixun.lbx.service.impl;

import com.yixun.lbx.entity.YxProBreedTreat;
import com.yixun.lbx.mapper.farm.BreedTreatMapper;
import com.yixun.lbx.service.BreedTreatService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BreedTreatServiceImpl implements BreedTreatService {

    private final BreedTreatMapper breedTreatMapper;

    public BreedTreatServiceImpl(BreedTreatMapper breedTreatMapper) {
        this.breedTreatMapper = breedTreatMapper;
    }

    @Override
    public Integer getCount(HashMap<String, Object> map) {
        return breedTreatMapper.getCount(map);
    }

    @Override
    public List<YxProBreedTreat> getListByPage(HashMap<String, Object> map) {
        return breedTreatMapper.getListByPage(map);
    }

    @Override
    public int addBreedTreat(HashMap<String, Object> map) {
        map.put("addTime", getDate());
        return breedTreatMapper.insertSelective(map);
    }

    @Override
    public int updateBreedTreat(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return breedTreatMapper.updateByPrimaryKeySelective(map);
    }

    @Override
    public int deleteBreedTreat(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return breedTreatMapper.deleteByPrimaryKey(map);
    }

    @Override
    public List<YxProBreedTreat> getObjByArgs(YxProBreedTreat breedTreat) {
        return breedTreatMapper.getObjByArgs(breedTreat);
    }

    @Override
    public List<YxProBreedTreat> getSearchListByPage(HashMap<String, String> map) {
        return breedTreatMapper.getSearchListByPage(map);
    }

    private String getDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }
}
